package com.yu.crm.controller;

import com.yu.crm.service.impl.TicketinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

@Component
public class TicketinfoServiceWithServletContextAware implements ServletContextAware {

    @Autowired
    private TicketinfoService ticketinfoService;

    @Override
    public void setServletContext(ServletContext servletContext) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            public void run() {
        ticketinfoService.deleteByTime();
        System.out.println("TicketinfoServiceWithServletContextAware" + new SimpleDateFormat("HH:mm:ss").format (new Date()));
            }
        }, 1000, 1000 * 60 * 60 * 24); // 此时为一天执行一次 每次延迟一秒执行
    }
}
